package cn.geminis.auth.context;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class LoginUser {

    public static String fullName() {
        var requestAttributes = RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
        return request.getHeader(HttpHeaders.AUTHORIZATION);
    }

    public static String userId() {
        return fullName().split("/")[1];
    }

    public static String username() {
        return fullName().split("/")[0];
    }
}
